package com.sunlight.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sunlight.dubbo.log.service.provider.LogProviderService;
import com.sunlight.dubbo.user.service.provider.UserProviderService;
import com.sunlight.service.UserServiceConsumer;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;


/**
 * Created by Nicholas on 16/10/25.
 */
@Service
public class UserServiceConsumerImpl implements UserServiceConsumer {

    @Resource
    UserProviderService userProviderService;

    @Resource
    LogProviderService logProviderService;

    public String addUser(JSONObject object) {
        userProviderService.saveUser(object);
        return "添加用户成功";
    }

    public String deleteUser(int id) {
        userProviderService.deleteUser(id);
        return "删除用户成功!!";
    }

    public String updateUser(JSONObject object) {
        JSONObject user=JSON.parseObject(JSON.toJSONString(object.get("user")));
        userProviderService.updateUser(user);
        JSONObject log=JSON.parseObject(JSON.toJSONString(object.get("log")));
        logProviderService.saveLog(log);
        return "更新用户成功!!";
    }

    public JSONObject getUser(int id) {
        return userProviderService.findUserById(id);
    }
}
